home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / cool.lha / ice / pisces / cpp / cpp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-04  |  8.8 KB  |  308 lines

  1.  
  2. /*
  3.  *    I n t e r n a l   D e f i n i t i o n s    f o r   C P P
  4.  *
  5.  * In general, definitions in this file should not be changed.
  6.  *
  7.  * Change History:
  8.  * 19-Jan-90  DKM   Added support for MVS and EBCDIC character set
  9.  */
  10.  
  11. #ifndef toupper
  12. #define toupper(c) ((c) + ('A' - 'a'))
  13. #endif /* no toupper */
  14. #ifndef tolower
  15. #define tolower(c) ((c) + ('a' - 'A'))
  16. #endif /* no tolower */
  17.  
  18. #ifndef    TRUE
  19. #define    TRUE        1
  20. #define    FALSE        0
  21. #endif
  22. #ifndef    EOS
  23. /*
  24.  * This is predefined in Decus C
  25.  */
  26. #define    EOS        '\0'        /* End of string        */
  27. #endif
  28. #define    EOF_CHAR    0        /* Returned by get() on eof    */
  29. #define NULLST        ((char *) NULL)    /* Pointer to nowhere (linted)    */
  30. #define    DEF_NOARGS    (-1)        /* #define foo vs #define foo()    */
  31. #define    DEF_BUILTIN    (-2)        /* Builtin defines              */
  32.  
  33. /*
  34.  * Non_display characters used for special markers.
  35.  *   The location of these is different in EBCDIC because the location
  36.  *   of the MAC_PARM table had be moved to start at char 1C.
  37.  */
  38. #if CHARSET == EBCDIC
  39. #define    DEF_MAGIC    0x19        /* Magic for #defines        */
  40. #define    TOK_SEP        0x1A        /* Token concatenation delim.    */
  41. #define COM_SEP        0x1B        /* Magic comment separator    */
  42. #else
  43. #define    DEF_MAGIC    0x1D        /* Magic for #defines        */
  44. #define    TOK_SEP        0x1E        /* Token concatenation delim.    */
  45. #define COM_SEP        0x1F        /* Magic comment separator    */
  46. #endif
  47.  
  48. /*
  49.  * Note -- in Ascii, the following will map macro formals onto DEL + the
  50.  * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will
  51.  * be ok as long as PAR_MAC is less than 33).  Note that the last PAR_MAC
  52.  * value is reserved for string substitution. 
  53.  *
  54.  * For EBCDIC, map macro formals x1C (decimal 28 + PAR_MAC) which
  55.  * also is OK as long as PAR_MAC is less than 33.  Note that this does
  56.  * overlap the code for BEL (decimal 47).  That means that you cannot
  57.  * use the  BEL char, ie '\a' in a #define macro.
  58.  */
  59. #if CHARSET == EBCDIC
  60. # define MAC_PARM        0x1C      /* Start at EBCDIC char x1C  */
  61. #else
  62. # define MAC_PARM     0x7F       /* Macro formals start here    */
  63. #endif
  64.  
  65. #if PAR_MAC >= 33
  66.     assertion fails -- PAR_MAC isn't less than 33
  67. #endif
  68. #define    LASTPARM    (PAR_MAC - 1)
  69.  
  70. /*
  71.  * Character type codes.
  72.  */
  73.  
  74. #define    INV        0        /* Invalid, must be zero    */
  75. #define    OP_EOE        INV        /* End of expression        */
  76. #define    DIG        1        /* Digit            */
  77. #define    LET        2        /* Identifier start        */
  78. #define    FIRST_BINOP    OP_ADD
  79. #define    OP_ADD        3
  80. #define    OP_SUB        4
  81. #define    OP_MUL        5
  82. #define    OP_DIV        6
  83. #define    OP_MOD        7
  84. #define    OP_ASL        8
  85. #define    OP_ASR        9
  86. #define    OP_AND        10        /* &, not &&            */
  87. #define    OP_OR        11        /* |, not ||            */
  88. #define    OP_XOR        12
  89. #define    OP_EQ        13
  90. #define    OP_NE        14
  91. #define    OP_LT        15
  92. #define    OP_LE        16
  93. #define    OP_GE        17
  94. #define    OP_GT        18
  95. #define    OP_ANA        19        /* &&                */
  96. #define    OP_ORO        20        /* ||                */
  97. #define    OP_QUE        21        /* ?                */
  98. #define    OP_COL        22        /* :                */
  99. #define    OP_CMA        23        /* , (relevant?)        */
  100. #define    LAST_BINOP    OP_CMA        /* Last binary operand        */
  101. /*
  102.  * The following are unary.
  103.  */
  104. #define    FIRST_UNOP    OP_PLU        /* First Unary operand        */
  105. #define    OP_PLU        24        /* + (draft ANSI standard)    */
  106. #define    OP_NEG        25        /* -                */
  107. #define    OP_COM        26        /* ~                */
  108. #define    OP_NOT        27        /* !                */
  109. #define    LAST_UNOP    OP_NOT
  110. #define    OP_LPA        28        /* (                */
  111. #define    OP_RPA        29        /* )                */
  112. #define    OP_END        30        /* End of expression marker    */
  113. #define    OP_MAX        (OP_END + 1)    /* Number of operators        */
  114. #define    OP_FAIL        (OP_END + 1)    /* For error returns        */
  115.  
  116. /*
  117.  * The following are for lexical scanning only.
  118.  */
  119.  
  120. #define    QUO        65        /* Both flavors of quotation    */
  121. #define    DOT        66        /* . might start a number    */
  122. #define    SPA        67        /* Space and tab        */
  123. #define    BSH        68        /* Just a backslash        */
  124. #define    END        69        /* EOF                */
  125.  
  126. /*
  127.  * These bits are set in ifstack[]
  128.  */
  129. #define    WAS_COMPILING    1        /* TRUE if compile set at entry    */
  130. #define    ELSE_SEEN    2        /* TRUE when #else processed    */
  131. #define    TRUE_SEEN    4        /* TRUE when #if TRUE processed    */
  132.  
  133. /*
  134.  * Define bits for the basic types and their adjectives
  135.  */
  136.  
  137. #define    T_CHAR          1
  138. #define    T_INT          2
  139. #define    T_FLOAT          4
  140. #define    T_DOUBLE      8
  141. #define    T_SHORT         16
  142. #define    T_LONG         32
  143. #define    T_SIGNED     64
  144. #define    T_UNSIGNED    128
  145. #define    T_PTR        256        /* Pointer            */
  146. #define    T_FPTR        512        /* Pointer to functions        */
  147.  
  148. /*
  149.  * The DEFBUF structure stores information about #defined
  150.  * macros.  Note that the defbuf->repl information is always
  151.  * in malloc storage.
  152.  */
  153.  
  154. typedef struct defbuf {
  155.     struct defbuf    *link;        /* Next define in chain    */
  156.         void (*expander)();             /* pointer to expander function */
  157.     char        *repl;        /* -> replacement    */
  158.     int        hash;        /* Symbol table hash    */
  159.     int        nargs;        /* For define(args)    */
  160.     char        name[1];    /* #define name        */
  161. } DEFBUF;
  162.  
  163. /*
  164.  * The FILEINFO structure stores information about open files
  165.  * and macros being expanded.
  166.  */
  167. /* WARNING: This structure is duplicated in defmacio.h */
  168. typedef struct fileinfo {
  169.     char        *bptr;        /* Buffer pointer    */
  170.     int        line;        /* for include or macro    */
  171.     FILE        *fp;        /* File if non-null    */
  172.     struct fileinfo    *parent;    /* Link to includer    */
  173.     char        *filename;    /* File/macro name    */
  174.     char        *progname;    /* From #line statement    */
  175.     unsigned int    unrecur;    /* For macro recursion    */
  176.     char*        buffer;     /* current input line    */
  177. } FILEINFO;
  178.  
  179. /*
  180.  * The SIZES structure is used to store the values for #if sizeof
  181.  */
  182.  
  183. typedef struct sizes {
  184.     short    bits;            /* If this bit is set,        */
  185.     short    size;            /* this is the datum size value    */
  186.     short    psize;            /* this is the pointer size    */
  187. } SIZES;
  188. /*
  189.  * nomacarg is a built-in #define on Decus C.
  190.  */
  191.  
  192. #ifdef    nomacarg
  193. #define    cput        output        /* cput concatenates tokens    */
  194. #else
  195. #if COMMENT_INVISIBLE
  196. #define    cput(c)        { if (c != TOK_SEP && c != COM_SEP) putchar(c); }
  197. #else
  198. #define    cput(c)        { if (c != TOK_SEP) putchar(c); }
  199. #endif
  200. #endif
  201.  
  202. #ifndef    nomacarg
  203. #define    streq(s1, s2)    (strcmp(s1, s2) == 0)
  204. #endif
  205.  
  206. /*
  207.  * Error codes.  VMS uses system definitions.
  208.  * Decus C codes are defined in stdio.h.
  209.  * Others are cooked to order.
  210.  */
  211.  
  212. #if defined(vms)
  213. #include        <ssdef.h>
  214. #include        <stsdef.h>
  215. #define IO_NORMAL    (SS$_NORMAL | STS$M_INHIB_MSG)
  216. #define    IO_ERROR    SS$_ABORT
  217. #endif
  218.  
  219. /*
  220.  * File access calls for OS2.
  221.  */
  222.  
  223. #if (HOST == SYS_OS2 || HOST == SYS_XENIX || HOST == SYS_VMS)
  224. #define F_OK        0    /* does file exist */
  225. #define X_OK        1    /* is it executable by caller */
  226. #define W_OK        2    /* writable by caller */
  227. #define R_OK        4    /* readable by caller */
  228. #endif
  229.  
  230. /* MVS headers already define F_OK, W_OK, and R_OK.  
  231.  * X_OK is not supported on MVS -- but we define it here
  232.  * to be the same as R_OK for cpp7.
  233.  */
  234. #if HOST == SYS_MVS
  235. #ifndef X_OK
  236. #define X_OK            R_OK    /* X_OK same as R_OK on MVS */
  237. #endif
  238. #endif
  239.  
  240. /*
  241.  * Note: IO_NORMAL and IO_ERROR are defined in the Decus C stdio.h file
  242.  */
  243. #ifndef    IO_NORMAL
  244. #define    IO_NORMAL    0
  245. #endif
  246. #ifndef    IO_ERROR
  247. #define    IO_ERROR    1
  248. #endif
  249.  
  250. /*
  251.  * Externs
  252.  */
  253.  
  254. extern int    line;            /* Current line number        */
  255. extern int    wrongline;        /* Force #line to cc pass 1    */
  256. extern char    type[];            /* Character classifier        */
  257. extern char    *tokenbuf;        /* Current input token        */
  258. extern int    tokenbsize;        /* Current size allocated in tokenbuf
  259.                        (not counting 1 byte for zero) */
  260. extern int    instring;        /* TRUE if scanning string    */
  261. extern int    inmacro;        /* TRUE if scanning #define    */
  262. extern int    errors;            /* Error counter        */
  263. extern DEFBUF    *macro;                /* Catches start of infinite macro */
  264. extern int    recursion;        /* Macro depth counter        */
  265. extern char    ifstack[BLK_NEST];    /* #if information        */
  266. #define    compiling ifstack[0]
  267. extern char    *ifptr;            /* -> current ifstack item    */
  268. extern char    *incdir[NINCLUDE];    /* -i directories        */
  269. extern char    **incend;        /* -> active end of incdir    */
  270. extern int    cflag;            /* -C option (keep comments)    */
  271. extern int    eflag;            /* -E option (ignore errors)    */
  272. extern int    nflag;            /* -N option (no pre-defines)    */
  273. extern int    rec_recover;        /* unwind recursive macros    */
  274. extern char    *preset[];        /* Standard predefined symbols    */
  275. extern char    *magic[];        /* Magic predefined symbols    */
  276. extern FILEINFO    *infile;        /* Current input file        */
  277. extern char    work[NWORK + 1];    /* #define scratch        */
  278. extern char    *workp;            /* Free space in work        */
  279. extern int    debug;            /* Debug level            */
  280. extern int    keepcomments;        /* Don't remove comments if set    */
  281. extern SIZES    size_table[];        /* For #if sizeof sizes        */
  282. extern char    *getmem();        /* Get memory or die.        */
  283. extern char    *incmem();        /* Increase size of block or die.  */
  284. extern DEFBUF    *lookid();        /* Look for a #define'd thing    */
  285. extern DEFBUF    *defendel();        /* Symbol table enter/delete    */
  286. extern char    *savestring();        /* Stuff string in malloc mem.    */
  287. extern char    *strcpy();
  288. extern char    *strcat();
  289. extern char    *strrchr();
  290. extern char    *strchr();
  291.  
  292. #if HOST != SYS_MVS
  293. extern long    time();
  294. #endif
  295.  
  296. #if (HOST != SYS_OS2 && HOST != SYS_XENIX && HOST != SYS_MVS && HOST != SYS_VMS)
  297. extern char    *sprintf();        /* Lint needs this        */
  298. #endif
  299.  
  300. typedef int (*internal_expander) ();
  301.  
  302. struct expander_pair {
  303.   char* name;
  304.   internal_expander function;
  305. };
  306.  
  307. extern struct expander_pair internal_macros[]; /* defines internal macro expanders */
  308.